package com.cwz.security.config;

import com.cwz.security.interceptor.HeaderInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @program: w-demo
 * @description: 拦截器配置
 * @author: Wen
 **/
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {
	// 不需要拦截地址
	private static final String[] excludeUrls = { "/login", "/logout", "/refresh" };

	@Override
	public void addInterceptors(InterceptorRegistry registry) {
		registry
			.addInterceptor(getHeaderInterceptor())
			.addPathPatterns("/**")
			.excludePathPatterns(excludeUrls)
			.order(-10);
	}

	/**
	 * @Description: 自定义请求头拦截器
	 * @Author: Wen
	 * @return: com.cwz.security.interceptor.HeaderInterceptor
	 **/
	private HeaderInterceptor getHeaderInterceptor() {
		return new HeaderInterceptor();
	}
}
